# Maintainer: Christian Rebischke <Chris.Rebischke[at]archlinux[dot]org>
# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
pkgname=packer
pkgver=1.8.6
pkgrel=1
pkgdesc="tool for creating identical machine images for multiple platforms from a single source configuration"
arch=('loong64' 'x86_64')
url="https://github.com/hashicorp/packer"
license=('MPL')
makedepends=('git' 'go' 'go-tools')
depends=('glibc')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/hashicorp/packer/archive/v${pkgver}.tar.gz")
sha512sums=('1e0e36959f1efb6eeae076da3d27c200f4888a6a08e759072ac6c767e1cc3e14876f09f96bdd208b788d32efde9420357afe3105337b7edcc87ba2d99966578c')
changelog=CHANGELOG.md

prepare() {
	export GOPATH="${srcdir}"
	export PATH="$PATH:$GOPATH/bin"
	mkdir -p "src/github.com/hashicorp"
	mv "${pkgname}-${pkgver}" "src/github.com/hashicorp/${pkgname}"
	sed -e '/VersionPrerelease = ""/ {N;N;N;d;}' -i "${srcdir}/src/github.com/hashicorp/${pkgname}/Makefile"
}

build() {
  cd "src/github.com/hashicorp/${pkgname}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external"
	go build -o packer-binary
}

# Currently broken
# check() {
#   cd "src/github.com/hashicorp/${pkgname}"
#   go test ./...
# }

package() {
	cd "src/github.com/hashicorp/${pkgname}"
	install -Dm755 packer-binary "${pkgdir}/usr/bin/packer"
	install -Dm644 contrib/zsh-completion/_packer "${pkgdir}"/usr/share/zsh/site-functions/_packer
}

# vim:set et sw=2 ts=2 tw=79:
